package leetcode;

import java.util.ArrayList;

/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Maximum_Depth_of_Binary_Tree {
    public int MaxDep = 0;
    public void inTree(TreeNode root,int len){
         if(root!=null){
             len++;
             if(MaxDep<len)
                 MaxDep=len;
             inTree(root.left,len);
             inTree(root.right,len);
         }
    }
    public int maxDepth(TreeNode root) {
        if(root==null){
            return MaxDep;
        }
        int len = 1;
        if(MaxDep<len){
            MaxDep=len;
        }
        inTree(root.left,len);
        inTree(root.right,len);
        return MaxDep;
    }
    public static void main(String[] args){
        TreeNode node1 = new TreeNode(4);
        node1.right = new TreeNode(2);
        node1.right.left = new TreeNode(3);
        node1.right.right = new TreeNode(4);
        node1.right.right.left = new TreeNode(5);
        Maximum_Depth_of_Binary_Tree m = new Maximum_Depth_of_Binary_Tree();
        System.out.println(m.maxDepth(node1));
    }
}